# Contributor: Guy Godfroy <guy.godfroy@gugod.fr>
# Maintainer: Guy Godfroy <guy.godfroy@gugod.fr>
pkgname=gotify
pkgver=2.5.0
pkgrel=0
pkgdesc="A simple server for sending and receiving messages in real-time per WebSocket"
url="https://gotify.net"
arch="all !aarch64 !riscv64"
license="MIT"
makedepends="go nodejs yarn"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/gotify/server/archive/refs/tags/v$pkgver.tar.gz
	gotify.initd
	gotify.confd
	10-config.patch
	"
builddir="$srcdir/server-$pkgver"
options="net"

build() {
	export LD_FLAGS="-w -s -X main.Version=$pkgver -X main.BuildDate=$(date "+%F-%T") -X main.Mode=prod";
	export NODE_OPTIONS="--openssl-legacy-provider"
	export CGO_CFLAGS="-D_LARGEFILE64_SOURCE"

	cd ui
	yarn
	yarn build
	cd ..
	go build -ldflags="$LD_FLAGS" -o gotify-server
}

check() {
	go test ./... \
		-skip "TestManagerSuite|TestNewManager_FaultyDB_expectError|TestCompatSuite|TestProjectPath"
}

package() {
	install -m755 -D "$builddir"/gotify-server \
		"$pkgdir"/usr/bin/gotify-server
	install -m644 -D "$builddir"/config.example.yml \
		"$pkgdir"/etc/gotify/config.yml
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
efc5c0f2dd35b851ea6158755a6e16f33f65f2ac6835bb931628e67f03bd0bed305153c0ee4975a95040834c4781d99fc4137aa18769232e4f553a2ac3b13c9b  gotify-2.5.0.tar.gz
b6138203f0e3fe8a8a1e25f462cec12c5a85bf2fe7f80190e32b2f26655d46390892464b3f557c4cf6eaff7cc6d557545ef4d053253bcb7e85c35630f82580e8  gotify.initd
7e7ad565905916b54e8a2b66b8f944a3f0e302e90a7af49894cd8748ff16f86ff8b42d7fffd8ca21bb0495c88fdf9b1429ef60224c16a2fe26d495816eb51c82  gotify.confd
ca3c017a47e9798602bdc66918ea045a5603e8988900ae012e944011e4b23d63f0d402e580965e8aa4431df0d0aa26dc7cbd704bd3ca5fadac8beba20e33fd63  10-config.patch
"
